<template>
  <Card title="风采审批">
    <Card :bordered="false">
      <Select style="width: 150px"
              v-model="selectData">
        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
      </Select>
      <Button type="primary" @click="query" style="margin-left: 15px">查询</Button>
    </Card>
    <Table border stripe ref="selection" size="small" :columns="columns" :data="nowData">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin: 5px" @click="showHtml(row)">查看内容</Button>
        <div style="margin: 10px">
        <div v-if="thearApprovalBO.cuParentId == 0">
          <div v-if="row.cuParentOne == 0 ">
            <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">审核</Button>
            <Button type="error" size="small" @click="remove(row)">驳回</Button>
          </div>
        </div>
        <div v-if="thearApprovalBO.cuParentId == 1">
          <div v-if="row.cuParentOne == 1">
            <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">审核</Button>
            <Button type="error" size="small" @click="remove(row)">驳回</Button>
          </div>
        </div>
        <div v-if="thearApprovalBO.cuParentId == 0">
          <div v-if="row.cuParentOne > 0">
            <span>无需操作</span>
          </div>
        </div>
        <div v-if="thearApprovalBO.cuParentId == 1">
          <div v-if="row.cuParentOne >= 2">
            <span>无需操作</span>
          </div>
        </div>
        </div>
        <Modal
          v-model="modal1"
          title="提示"
          @on-ok="okDel">
          <p>确定要审核通过吗?</p>
        </Modal>
        <Modal
          v-model="modal2"
          title="提示"
          @on-ok="okDel2">
          <p>确定要驳回吗?</p>
        </Modal>
        <Modal
          fullscreen
          width="500"
          v-model="dataHtmlBool"
          title="详细内容"
        >
          <div v-html="dataHtml"></div>
        </Modal>
      </template>
    </Table>
    <Page :total="dataCount" :page-size="thearApprovalBO.size" @on-change="changePage"
          @on-page-size-change="_nowPageSize"
          show-total show-sizer show-elevator/>

  </Card>
</template>

<script>
export default {
  name: 'thear-approval',
  data () {
    return {
      auditDate: {},
      modal2: false,
      modal1: false,
      selectData: '0',
      dataHtmlBool: false,
      dataHtml: null,
      nowData: [],
      columns: [
        {
          title: '序号',
          key: 'cuThearId'
        },
        {
          title: '标题',
          key: 'cuThearTitle'
        },
        {
          title: '创建时间',
          key: 'cuThearDate'
        },
        {
          title: '审批理由',
          key: 'cuThearMessage'
        },
        {
          title: '用户名',
          key: 'cuUsername'
        },
        {
          title: '审核',
          key: 'cuParentOne',
          render: (h, params) => {
            if (this.thearApprovalBO.cuParentId == 0) {
              if (params.row.cuParentOne == 0) {
                return h('span', '未审核')
              } else if (params.row.cuParentOne == 1) {
                return h('span', '已审核')
              } else if (params.row.cuParentOne == 3) {
                return h('span', '已驳回')
              }
            } else if (this.thearApprovalBO.cuParentId == 1) {
              if (params.row.cuParentOne == 1) {
                return h('span', '未审核')
              } else if (params.row.cuParentOne == 2) {
                return h('span', '已审核')
              } else if (params.row.cuParentOne == 4) {
                return h('span', '已驳回')
              }
            }
          }
        },

        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      dataCount: 0,
      thearApprovalBO: {
        cuThearId: null,
        cuAdminId: this.$store.state.user.userAll.cuAdminId,
        cuParentId: this.$store.state.user.userAll.cuParentId,
        cuTownId: this.$store.state.user.userAll.cuOnlyId,
        cuParentOne: '0',
        current: 1,
        size: 10
      },
      cityList: [
        {
          value: '0',
          label: '未审核'
        }, {
          value: '1',
          label: '已审核'
        }, {
          value: '2',
          label: '已驳回'
        }
      ]
    }
  },
  methods: {
    remove (row) {
      this.thearApprovalBO.cuThearId = row.cuThearId
      this.modal2 = true
    },
    show (row) {
      this.thearApprovalBO.cuThearId = row.cuThearId
      this.modal1 = true
    },
    okDel2 () {
      if (this.thearApprovalBO.cuParentId == 0) {
        this.thearApprovalBO.cuParentOne = 3
      } else if (this.thearApprovalBO.cuParentId == 1) {
        this.thearApprovalBO.cuParentOne = 4
      }
      this.$axios_supermall.post('/thear/thearAudit', this.thearApprovalBO).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.success('驳回成功')
          this.query()
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    },
    okDel () {
      if (this.thearApprovalBO.cuParentId == 0) {
        this.thearApprovalBO.cuParentOne = 1
      } else if (this.thearApprovalBO.cuParentId == 1) {
        this.thearApprovalBO.cuParentOne = 2
      }

      this.$axios_supermall.post('/thear/thearAudit', this.thearApprovalBO).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.success('审核成功')
          this.query()
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    },
    showHtml (row) {
      this.dataHtml = row.cuThearCenter
      this.dataHtmlBool = true
    },
    query () {
      if (this.thearApprovalBO.cuParentId == 1) {
        if (this.selectData == '0') {
          this.thearApprovalBO.cuParentOne = 1
        } else if (this.selectData == '1') {
          this.thearApprovalBO.cuParentOne = 2
        } else if (this.selectData == '2') {
          this.thearApprovalBO.cuParentOne = 4
        }
      } else {
        this.thearApprovalBO.cuParentOne = this.selectData
        if (this.selectData == '2') {
          this.thearApprovalBO.cuParentOne = 3
        }
      }
      this.$Loading.start()
      this.$axios_supermall.post('/thear/queryApproval', this.thearApprovalBO).then(resp => {
        if (resp.data.code == 0) {
          let data = resp.data.data
          this.nowData = data.records
          this.dataCount = data.total
          this.thearApprovalBO.current = data.current;
          this.thearApprovalBO.size = data.size;
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    },
    changePage (index) {
      this.thearApprovalBO.size = index
    },
    _nowPageSize (index) {
      this.thearApprovalBO.current = index
      this.query()
    }
  },
  mounted () {
    this.query();
    (JSON.stringify(this.$store.state.user.userAll))
  }
}
</script>

<style scoped>

</style>
